import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lcapp/api/interface/user_api.dart';
import 'package:lcapp/api/request/response_data.dart';
import 'package:lcapp/config/const_config.dart';
import 'package:lcapp/data/withdraw_entity_entity.dart';
import 'package:lcapp/model/refresh/refresh.dart';
import 'package:lcapp/widget/asr_app_bar.dart';

class MinGetMoneyListPage extends StatefulWidget {
  const MinGetMoneyListPage({Key? key}) : super(key: key);

  @override
  State<MinGetMoneyListPage> createState() => _MinGetMoneyListPageState();
}

class _MinGetMoneyListPageState extends State<MinGetMoneyListPage> {

  int page = 1;
  int size = 10;
  List<WithdrawEntityEntity> list = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getList();
  }

  getList()async{
    ResponseData res  = await UserAPI.minGetMoneyList({
      'page':page,
      'size':size
    });
    if(res.code==200){
      if(page==1){
        list.clear();
      }
      List arr = res.data??[];
      for (var element in arr) { 
        WithdrawEntityEntity entity = WithdrawEntityEntity().fromJson(element);
        list.add(entity);
      }
    }
    if(mounted){setState(() {
    });}
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: bgColor,
      appBar: AsrAppBar(
        barColor: Colors.white,
        backgroundColor: defaultBarColor,
        titleText: '提现记录',
      ),
      body: EasyRefresh(
        header: myRefreshHeader(),
        footer: myRefreshFooter(),
        onRefresh: ()async{
          page=1;
          getList();
        },
        onLoad: ()async{
          page += 1;
          getList();
        },
        child: ListView.builder(
            padding: EdgeInsets.symmetric(vertical: 30.w,horizontal: 30.w),
            itemCount: list.length,
            itemBuilder: (context,index){
              WithdrawEntityEntity entity = list[index];
              return GestureDetector(
                onTap: (){},
                child: Container(
                  margin: EdgeInsets.only(bottom: 30.w),
                  padding: EdgeInsets.all(30.w),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10.w)
                  ),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Expanded(child:Text(entity.state==0?'提现中':entity.state==1?'提现成功':'提现失败',style: TextStyle(
                              color: Colors.black,
                              fontSize: 30.sp,
                              fontWeight: FontWeight.w600
                          )),
                          ),
                          SizedBox(width: 20.w,),
                          Text('${entity.amount}元',style: TextStyle(
                              color: defaultBarColor,
                              fontSize: 30.sp,
                              fontWeight: FontWeight.w600
                          )),
                        ],
                      ),
                      SizedBox(height: 30.w,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                         Text('提现时间:',style: TextStyle(
                              fontSize: 25.sp,
                              color:Colors.black
                          )),
                          SizedBox(width: 20.w,),
                          Expanded(child: Text('${entity.createTime}',style: TextStyle(
                              fontSize: 25.sp,
                              color:Colors.black
                          ))),
                        ],
                      ),
                      SizedBox(height: 10.w,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text('提现类型:',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          )),
                          SizedBox(width: 20.w,),
                          Expanded(child: Text(entity.withdrawType ==0 ? '支付宝转账':'银行卡转账',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          ))),
                        ],
                      ),
                      SizedBox(height: 10.w,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text('真实姓名:',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          )),
                          SizedBox(width: 20.w,),
                          Expanded(child: Text(entity.realName??'',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          ))),
                        ],
                      ),
                      SizedBox(height: 10.w,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text('提现账号:',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          )),
                          SizedBox(width: 20.w,),
                          Expanded(child: Text(entity.withdrawType==0?entity.alipay??'':entity.unionpay??'',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          ))),
                        ],
                      ),
                      SizedBox(height: 10.w,),
                      Visibility(child: Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text('开户银行:',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          )),
                          SizedBox(width: 20.w,),
                          Expanded(child: Text(entity.openBank??'',style: TextStyle(
                              fontSize: 25.sp,
                              color:Color(0xff666666)
                          ))),
                        ],
                      ),visible: entity.withdrawType==1,),
                    ],
                  ),
                ),
              );
            }
        ),
      ),
    );
  }
}
